//
//  ZineViewmb.m
//  YZZX
//
//  Created by Easaa on 15/6/5.
//  Copyright (c) 2015年 Easaa. All rights reserved.
//

#import "ZineViewmb.h"
#import "Zineviewnew.h"

@interface ZineViewmb ()<UIScrollViewDelegate>
{
    UIScrollView  *_scrollviewbg;
    NSMutableArray *DataNewModel;

}

@end

@implementation ZineViewmb


- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    
    self.RefreshBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.RefreshBut.frame = CGRectMake(Dev_ScreenWidth-32, 64-32, 32, 32);
    [self.RefreshBut setImage:[UIImage imageNamed:@"action_refresh"] forState:UIControlStateNormal];
    [self.RefreshBut setImage:[UIImage imageNamed:@"action_refresh"] forState:UIControlStateHighlighted];
    // self.RefreshBut.hidden =YES;
    
    [self.RefreshBut addTarget:self action:@selector(newshauxin) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIBarButtonItem *negativeSpacerRight = [[UIBarButtonItem alloc]
                                            
                                            initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                            
                                            target:nil action:nil];
    
    /**
     
     *  width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和边界间距为5pix，所以width设为-5时，间距正好调整
     
     *  为0；width为正数时，正好相反，相当于往左移动width数值个像素
     
     */
    
    negativeSpacerRight.width = -12;
    
    UIBarButtonItem *rightBarBtItem = [[UIBarButtonItem alloc] initWithCustomView:self.RefreshBut];
    
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacerRight, rightBarBtItem, nil];
    
  
    DataNewModel = [[NSMutableArray alloc]init];
    
    for (HeadZlineMassgeModel *cellmodel in self.HeadmodelArry)
    {
        //Tagcount = cellmodel.Articles.count+Tagcount;
        [DataNewModel addObjectsFromArray:cellmodel.Articles];
        
    }

    
    // UIScrollView创建
    _scrollviewbg = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, Dev_ScreenWidth, Dev_ScreenHeight-64)];
    _scrollviewbg.contentSize =CGSizeMake(Dev_ScreenWidth*DataNewModel.count, Dev_ScreenHeight);
    _scrollviewbg.delegate =self;
    _scrollviewbg.bounces = NO;
    [_scrollviewbg setPagingEnabled:YES];
    _scrollviewbg.showsHorizontalScrollIndicator = NO;
    _scrollviewbg.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollviewbg];
    
    
    
    for (int i= 0; i<DataNewModel.count; i++)
    {
        Zineviewnew  *ViewZline =[[Zineviewnew alloc]initWithEstablish:DataNewModel[i]];
        ViewZline.frame =CGRectMake(Dev_ScreenWidth*i, 0, Dev_ScreenWidth, Dev_ScreenHeight-64);
        ViewZline.tag = i;
        [_scrollviewbg addSubview:ViewZline];
        
    }
    
    
    NSInteger ScreenWidthCount;
    ScreenWidthCount = 0;
    
    for (int i= 0; i<self.headmdoelcount; i++)
    {
       
        HeadZlineMassgeModel *cellmodel = self.HeadmodelArry[i];
        ScreenWidthCount = cellmodel.Articles.count +ScreenWidthCount;
 
    }

    
    
    
    
    _scrollviewbg.contentOffset = CGPointMake(Dev_ScreenWidth*(ScreenWidthCount + self.Tag), 0);

}

//刷新
- (void)newshauxin
{
    
    for ( UIView  *View in _scrollviewbg.subviews)
    {
        if([View isKindOfClass:[Zineviewnew class]])
        {
           if(_scrollviewbg.contentOffset.x/Dev_ScreenWidth == View.tag)
           {
               [(Zineviewnew *)View ButMenuBseletor];
   
           }

        }
    }

 


}




@end









